import request from '@/utils/request';

/**
 * JOPENS在线用户监控
 * @param params
 * @returns
 */
export const fetchJopensConfig = (params: any) => {
  return request({
    url: 'jopensConfig/list',
    params,
  });
};

/**
 * 新增 JOPENS 配置
 */
export const createJopensConfig = (data: any) => {
  return request({
    url: 'jopensConfig/add',
    method: 'POST',
    data,
  });
};

/**
 * 更新 JOPENS 配置
 * @param data
 * @returns
 */
export const updateJopensConfig = (data: any) => {
  return request({
    url: 'jopensConfig/update',
    method: 'PUT',
    data,
  });
};

export const deleteJopensConfig = (ids: number[]) => {
  return request({
    url: `jopensConfig/delete/${ids.join()}`,
    method: 'DELETE',
  });
};

/**
 * 更新JOPENS 期望用户
 */
export const updateJopensUser = (data: any) => {
  return request({
    url: 'jopensConfig/updateDesires',
    method: 'POST',
    data,
  });
};
/**
 * 更新JOPENS 期望用户监控状态
 */
export const updateJopensUserMonitorStatus = (data: any) => {
  return request({
    url: 'jopensConfig/enable',
    method: 'POST',
    data,
  });
};

/**
 * 开启波形
 */
export const enableWave = (id: any) => {
  return request({
    url: `data/startGroup/${id}`,
  });
};

/**
 * 关闭波形
 */
export const disableWave = (id: any) => {
  return request({
    url: `data/stopGroup/${id}`,
  });
};

/**
 * 网络设备监控
 */
export const fetchNodeList = (params: any) => {
  return request({
    url: 'node/list',
    params,
  });
};

/**
 * 更新网络设备
 */
export const updateNode = (data: any) => {
  return request({
    url: 'node/update',
    method: 'PUT',
    data,
  });
};

export function deleteNode(ids: string) {
  return request({
    url: '/node/delete/' + ids,
    method: 'delete',
  });
}

/**
 * 新增网络设备
 */
export const createNode = (data: any) => {
  return request({
    url: 'node/add',
    method: 'POST',
    data,
  });
};

/**
 * 更新设备状态
 */
export const enableNode = (data: any) => {
  return request({
    url: 'node/enable',
    method: 'PUT',
    data,
  });
};

/**
 * 进程监控列表
 */
export const fetchProcessMonitors = (params: any) => {
  return request({
    url: '/processMonitor/list',
    params,
  });
};

/**
 * 进程监控新增
 */
export const createProcessMonitor = (data: any) => {
  return request({
    url: '/processMonitor/add',
    method: 'POST',
    data,
  });
};
/**
 * 进程监控更新
 */
export const updateProcessMonitor = (data: any) => {
  return request({
    url: '/processMonitor/update',
    method: 'PUT',
    data,
  });
};

/**
 * 进程监控开关
 */
export const enableProcessMonitor = (data: any) => {
  return request({
    url: '/processMonitor/enable',
    method: 'POST',
    data,
  });
};

/**
 * 进程监控删除
 */
export const deleteProcessMonitor = (ids: number[]) => {
  return request({
    url: `processMonitor/delete`,
    method: 'DELETE',
    data: {
      monitorIds: ids,
    },
  });
};

export const fetchServer = () => {
  return request({
    url: 'serverMonitor/selectList',
  });
};

/**
 * ntp 监控列表
 */
export const fetchNtpMonitor = (params: any) => {
  return request({
    url: 'ntpMonitor/list',
    params,
  });
};

/**
 * ntp 监控新增
 */
export const createNtpMonitor = (data: any) => {
  return request({
    url: 'ntpMonitor/add',
    method: 'POST',
    data,
  });
};

/**
 * ntp 监控更新
 */
export const updateNtpMonitor = (data: any) => {
  return request({
    url: 'ntpMonitor/edit',
    method: 'PUT',
    data,
  });
};

/**
 * ntp 监控开关
 */
export const enableNtpMonitor = (data: any) => {
  return request({
    url: 'ntpMonitor/enable',
    method: 'POST',
    data,
  });
};

/**
 * ntp 监控 删除
 */
export const deleteNtpMonitor = (ids: number[]) => {
  return request({
    url: `ntpMonitor/deleteBatch/${ids.join()}`,
    method: 'DELETE',
  });
};

/**
 * 服务器监控 列表
 */
export const fetchServerMonitors = (params: any) => {
  return request({
    url: 'serverMonitor/list',
    params,
  });
};

/**
 * 服务器监控 新增
 */
export const createServerMonitors = (data: any) => {
  return request({
    url: 'serverMonitor/add',
    method: 'POST',
    data,
  });
};

/**
 * 服务器监控 修改
 */
export const updateServerMonitors = (data: any) => {
  return request({
    url: 'serverMonitor/update',
    method: 'PUT',
    data,
  });
};

/**
 * 服务器监控 开关
 * @param data
 * @returns
 */
export const enableServerMonitors = (data: any) => {
  return request({
    url: 'serverMonitor/enable',
    method: 'POST',
    data,
  });
};

/**
 * 服务器监控 删除
 */
export const deleteServerMonitors = (ids: number[]) => {
  return request({
    url: `serverMonitor/delete`,
    method: 'DELETE',
    data: {
      monitorIds: ids,
    },
  });
};

/**
 * 网络监控-列表
 */
export const fetchNetList = (params: any) => {
  return request({
    url: 'net/list',
    params,
  });
};

/**
 * 网络监控-新增
 */
export const createNet = (data: any) => {
  return request({
    url: 'net/add',
    method: 'POST',
    data,
  });
};

/**
 * 网络设备-详情
 */
export const fetchNet = (id: number) => {
  return request({
    url: `net/detail/${id}`,
  });
};

/**
 * 网络设备-更新
 */
export const updateNet = (data: any) => {
  return request({
    url: `net/update`,
    method: 'PUT',
    data,
  });
};

/**
 * 网络设备-删除
 */
export const deleteNet = (data: any) => {
  return request({
    url: `net/delete`,
    method: 'DELETE',
    data,
  });
};
/**
 * 网络设备-删除
 */
export const enableNet = (data: any) => {
  return request({
    url: `net/enable`,
    method: 'POST',
    data,
  });
};

/**
 * 定时任务配置
 */
export const fetchScheduled = (name: string) => {
  return request({
    url: `scheduled/detail/${name}`,
  });
};

/**
 * 更新定时任务
 */
export const updateScheduled = (data: any) => {
  return request({
    url: 'scheduled/update',
    method: 'PUT',
    data,
  });
};

/**
 * 启用/停用定时任务
 */
export const enableScheduled = (data: any) => {
  return request({
    url: 'scheduled/enable',
    method: 'POST',
    data,
  });
};

/**
 * 立即运行定时任务
 */
export const runScheduled = (id: number) => {
  return request({
    url: `scheduled/run/${id}`,
  });
};

/***********************************数据库监控***********************************/
/**
 * 数据库选项
 */
export const getDatabase = () => {
  return request({
    url: 'databaseMonitor/option',
  });
};

/**
 * 数据库综合历史指标
 */
export const getDatabaseHistory = () => {
  return request({
    url: 'databaseMonitor/history',
  });
};

/**
 * 单个数据库历史指标
 */
export const getDatabaseDbHistory = () => {
  return request({
    url: 'databaseMonitor/dbHistory',
  });
};

/**
 * SQL下拉
 */
export const getDatabaseSqlOption = (data: any) => {
  return request({
    url: 'databaseMonitor/sqlOption',
    method: 'POST',
    data,
  });
};

/**
 * SQL语句
 */
export const getDatabaseSqlList = (params: any) => {
  return request({
    url: 'databaseMonitor/sqlList',
    params,
  });
};
